package com.ycsj.goldmedalnewconcept.teacher.activity;

import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.just.agentweb.AgentWeb;
import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.base.BaseApplication;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.HttpAddress;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 习题分析H5
 * Created by Administrator on 2019/5/5 0005.
 */

public class TeacherAppraisalTestActivity extends BaseActivity {

    @BindView(R.id.rl_content)
    RelativeLayout rlContent;

    @BindView(R.id.tv_title)
    TextView tvTitle;

    private AgentWeb mAgentWeb;

    private String school_id;
    private String ttel;
    private String classnum;
    private String total;
    private String unit;

    //习题分析的H5页面的URL
    private String URL;

    /**
     * 跳转到当前Activity的方法
     *
     * @return
     */
    public static void startActivity(Context context, String school_id, String ttel,
                                     String classnum, String unit, String total) {
        Intent intent = new Intent(BaseApplication.context, TeacherAppraisalTestActivity.class);
        intent.putExtra("school_id", school_id);
        intent.putExtra("ttel", ttel);
        intent.putExtra("classnum", classnum);
        intent.putExtra("unit", unit);
        intent.putExtra("total", total);
        context.startActivity(intent);
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_pet_helper;
    }

    @Override
    protected void init() {

        initStateBar();

        initIntent();

        //初始化标题
        initTitle();

        //初始化配置
        initAndAddWebView();
    }

    /**
     * 获取传递参数
     */
    private void initIntent() {
        Intent intent = getIntent();
        school_id = intent.getStringExtra("school_id");
        ttel = intent.getStringExtra("ttel");
        classnum = intent.getStringExtra("classnum");
        unit = intent.getStringExtra("unit");
        total = intent.getStringExtra("total");


        //外网正式服
        URL = HttpAddress.QUESTIONFENXI + "?type=2&" +
                "school_id=" + school_id + "&ttel=" + ttel + "&classnum=" + classnum + "&unit=" + unit + "&total=" + total + "&platform=5";
    }

    /**
     * 初始化标题
     */
    private void initTitle() {
        tvTitle.setText("Unit" + unit + "习题分析");
    }

    /**
     * 初始化WebView并添加到视图
     */
    private void initAndAddWebView() {
        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(rlContent, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready()
                .go(URL);
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (mAgentWeb.handleKeyEvent(keyCode, event)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onPause() {
        mAgentWeb.getWebLifeCycle().onPause();
        super.onPause();

    }

    @Override
    protected void onResume() {
        mAgentWeb.getWebLifeCycle().onResume();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        mAgentWeb.getWebLifeCycle().onDestroy();
        super.onDestroy();
    }

    /**
     * 点击事件
     *
     * @param v
     */
    @OnClick(R.id.iv_back)
    public void clickEvent(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                //返回
                finish();
                break;
        }
    }


}
